/*hello_module.c*/
#include<linux/init.h>
#include<linux/time.h>
#include<linux/wait.h>
#include<linux/kernel.h>

#include<linux/jiffies.h>
#include<linux/types.h>
#include<linux/module.h>
#include<linux/device.h>
#include <linux/sched.h>
#include<linux/delay.h>
MODULE_LICENSE("GPL");

#define SERIAL_IMX_MAJOR        207
#define MINOR_START	        16
#define DEV_NAME		"helloworld"

static int hello_init(void)
{
	//uint8_t i;
	uint64_t jif_tmp;
	wait_queue_head_t wait;
//	register_chrdev_region();
	init_waitqueue_head(&wait);
	printk(KERN_EMERG "Hello Linux Driver!%d\n",HZ);
	//wait_event_interruptible_timeout(wait,0,5*HZ);	//超时方式，等待过程不进入运行队列
	//wait_event_interruptible_timeout
	//jif_tmp=jiffies;	//直接读32位jiffies
	jif_tmp=get_jiffies_64();		//原子的取得64位jiffies值	
	printk(KERN_EMERG "delay_5%llu\n",jif_tmp);
	jif_tmp+=5*HZ;
	printk(KERN_EMERG "delay_5%llu\n",jif_tmp);
	while(time_before(jiffies,jif_tmp))
	{
		schedule();		//会让出处理器
		//cpu_relax();	//独占处理器
	}
	printk(KERN_EMERG "delay_10\n");
	ndelay(100);
	printk(KERN_EMERG "delay_11\n");
	//for(i=0;i<10;i++)
	{
		udelay(100);
	}
	printk(KERN_EMERG "delay_12\n");
	mdelay(5000);
	printk(KERN_EMERG "delay_13\n");

	return 0;
}

static void hello_exit(void)
{
	printk(KERN_EMERG "Hello Diver Exit !\n");
}
module_init(hello_init);
module_exit(hello_exit);
